﻿$(function() {
    JSUtility.url = "../../Handler/AjaxHandle.ashx";
    JSUtility.param.ClassName = "OA.Bll.Project.ContractsClientPresenter";
    autoResize({ dataGrid: '#Grid', callback: Initlist });

    JSUtility.window_edit = $('#Add').window({
        iconCls: 'icon-add',
        zIndex: 1000,
        draggable: true,
        resizable: false,
        shadow: true,
        inline: true,
        modal: true,
        title: '添加合同客户信息',
        collapsible: false,
        minimizable: false,
        maximizable: false,
        closable: true,
        width: 450,
        // height: 200,
        closed: true,
        onOpen: function() {
            $('#Add').parent().css("left", "25%");
            $('#Add').parent().next().css("left", "25%");
            $('#Add').parent().next().css("top", "25%");
            $('#Add').parent().css("top", "25%");
        }
    });
    JSUtility.window_edit_title = "合同客户信息";
    $('#Add').show();
    JSUtility.window_edit_form = $("#Add").find("form");
});

var contractsName = "";
function Initlist(size) {
    var contractsId;
    if (self.parent.parent.projectInfoManager) {
        contractsId = self.parent.parent.parent.contracts_id;
        contractsName = self.parent.parent.parent.contracts_Name;
    } else {
        contractsId = self.parent.parent.contracts_id;
        contractsName = self.parent.parent.contracts_Name;
    }
    JSUtility.param.Options["ContractId"] = contractsId;
    JSUtility.replenish = function() {
        $("#ContractId").val(contractsId);
    };
    $("#ContractId").attr("readonly", "readonly");

    JSUtility.param.Method = "Search";
    JSUtility.grid = $('#Grid').datagrid({
        tilte: '合同客户基础信息',
        iconCls: 'icon-save',
        width: size.width,
        height: size.height,
        pageSize: Math.round(size.height / 25),
        pageList: [Math.round(size.height / 25)],
        nowrap: true,
        striped: true,
        url: JSUtility.url,
        queryParams: { "json": $.toJSON(JSUtility.param) },
        sortName: 'Id',
        sortOrder: 'desc',
        idField: 'Id',
        frozenColumns: [[{ title: '编号', field: 'Id', width: 80, sortable: true}]],
        columns: [[
                    { title: '合同外部编号', field: 'ContractId', width: 80 },
                    { title: '合同名称', field: 'ContractName', width: 100, formatter: function() {
                        return "<span>" + contractsName + "</span>";
                    }
                    },
                    { title: '客户名称', field: 'ClientName', width: 100 },
                    { title: '职位名称', field: 'PostionName', width: 120 },
                    { title: '联系方式', field: 'ContactMethod', width: 120 }
                  ]],
        pagination: true,
        rownumbers: true,
        singleSelect: true,
        toolbar: [
                    {
                        text: '添加',
                        iconCls: 'icon-add',
                        handler: JSUtility.add
                    }, '-',
                    {
                        text: '修改',
                        iconCls: 'icon-edit',
                        handler: JSUtility.update
                    }, '-',
                    {
                        text: '删除',
                        iconCls: 'icon-remove',
                        handler: JSUtility.del
                    }, '-',
                    {
                        text: '查询',
                        iconCls: 'icon-search',
                        handler: JSUtility.search
                    }
                  ]
    });
}
function Add() {
    $('#Add').window({ title: '添加合同客户信息', iconCls: 'icon-add', closed: false });
}
function Update() {
    $('#Add').window({ title: '修改合同客户信息', iconCls: 'icon-edit', closed: false });
}
function Search() {
    $('#Add').window({ title: '查询合同客户信息', iconCls: 'icon-search', closed: false });
}